package ma.cdm.compteRendu.bo;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;

/**
 * Role entity. @author Limouri Anouar
 */
@Entity
@Table(name="ROLE")

public class Role  implements java.io.Serializable {

	// Fields

     private Long idrole;
     private String libellerole;
     private String descriptionrole;
     private Set<Action> actions = new HashSet<Action>(0);
     private Set<PersonneRole> personneRoles = new HashSet<PersonneRole>(0);

	// Constructors

	/** default constructor */
	public Role() {
	}

    
    /** full constructor */
    public Role(String libellerole, String descriptionrole, Set<Action> actions, Set<PersonneRole> personneRoles) {
        this.libellerole = libellerole;
        this.descriptionrole = descriptionrole;
        this.actions = actions;
        this.personneRoles = personneRoles;
    }

   
    // Property accessors
    @GenericGenerator(name="generator", strategy="increment")@Id @GeneratedValue(generator="generator")
    
    @Column(name="IDROLE", unique=true, nullable=false)

    public Long getIdrole() {
        return this.idrole;
    }
    
    public void setIdrole(Long idrole) {
        this.idrole = idrole;
    }
    
    @Column(name="LIBELLEROLE", length=50)

    public String getLibellerole() {
        return this.libellerole;
    }
    
    public void setLibellerole(String libellerole) {
        this.libellerole = libellerole;
    }
    
    @Column(name="DESCRIPTIONROLE", length=100)

    public String getDescriptionrole() {
        return this.descriptionrole;
    }
    
    public void setDescriptionrole(String descriptionrole) {
        this.descriptionrole = descriptionrole;
    }
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinTable(name="actionsdurole", joinColumns = { 
        @JoinColumn(name="IDROLE", nullable=false, updatable=false) }, inverseJoinColumns = { 
        @JoinColumn(name="IDACTION", nullable=false, updatable=false) })

    public Set<Action> getActions() {
        return this.actions;
    }
    
    public void setActions(Set<Action> actions) {
        this.actions = actions;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="role")

    public Set<PersonneRole> getPersonneRoles() {
        return this.personneRoles;
    }
    
    public void setPersonneRoles(Set<PersonneRole> personneRoles) {
        this.personneRoles = personneRoles;
    }
   

}